Desperate help using PHP's $_SERVER["DOCUMENT_ROOT"] on a web server?

Posted by Nickersoft on Stack Overflow See other posts from Stack Overflow or by Nickersoft
Published on 2013-11-01T03:47:59Z Indexed on 2013/11/01 3:53 UTC
Read the original article Hit count: 87

I've spent the past few months building a website on localhost. Throughout the site, instead of using relative paths, I used $_SERVER["DOCUMENT_ROOT"] to access the root of my server so I could reference files from there. However, I just decided to upload my site to 000webhost. As I soon found out, and for those of you who use them, you are probably aware, that their server root is different than your actual directory in which you upload your files. I believe it's virtual hosting... anyway, my $_SERVER["DOCUMENT_ROOT"] now throws errors along the lines of this on the site:

Warning: include_once() [function.include-once]: open_basedir restriction in effect. File(/usr/local/apache/htdocs/mypath) is not within the allowed path(s)

Every other site I looked at said that you should just replace $_SERVER["DOCUMENT_ROOT"] with the home directory provided to you by 000webhost. However, if I want to change hosting services in the future, I'm screwed. Is there any way to use $_SERVER to access a set virtual directory or use htaccess or something to make my code work? I tried using DocumentRoot in a htaccess file in my root directory, but it threw a 404 error when trying to access the page.

I'm in desperate need... can anyone help me?

© Stack Overflow or respective owner

Related posts about php

Related posts about .htaccess